﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "WMS_Line";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div id = "uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
<form name = "form1" method="post" id="form1">
    <table>
        <tr>
            <th style="padding:20px;"> Excel：</th>
            <td style="padding:20px;">
                <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                <a href = "javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                <span class="uploading">@Resource.Uploading</span>
            </td>
        </tr>
    </table>
    <div class="endbtndiv">
        <a id = "btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
        <a id = "btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
    </div>
</form>
</div>
<table style="width:100%">
<tbody>
    <tr>
        <td style="width:330px;vertical-align: top">
             <div class="mvctool">
             </div>
            <table id="ListParent"></table>
        </td>        <td style="width:3px;"></td>
        <td style="vertical-align:top">
             <div class="mvctool">
                 <input id="txtQuery" type="text" class="searchText" />
                 @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,ref perm, "Query", true)
                 @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create,ref perm, "Create", true)
                 @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit,ref perm, "Edit", true)
                 @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete,ref perm, "Delete", true)
                 @Html.ToolButton("btnImport", "fa fa-level-down", Resource.Import, ref perm, "Import", true)
                 @Html.ToolButton("btnExport", "fa fa-level-up", Resource.Export, ref perm, "Export", true)
             </div>
            <table id="List"></table>
        </td>
    </tr>
</tbody>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#ListParent').datagrid({
            url: '@Url.Action("GetListParent")',
            width:430,
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function(data) {            },
            columns: [[
                { field: 'Id', title: 'Id', width: 80,hidden:true },
                { field: 'Code', title: 'Code', width: 80,sortable:true },
                { field: 'Name', title: 'Name', width: 80,sortable:true }
            ]]
         ,onClickRow: function(index, row) {
             $('#List').datagrid("load", { ParentId: row.Id });
}
        }).datagrid('getPager').pagination({ showPageList: false, showRefresh: false });
         $(window).resize(function() {
             resizeLayout();
         });
        $('#List').datagrid({
            url: '@Url.Action("GetList")?parentId=0',
            width:SetGridWidthSub(450),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function(data) {                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'Id', title: 'Id', width: 80,hidden:true },
                { field: 'HeaderId', title: 'HeaderId', width: 80,sortable:true },
                { field: 'LineName', title: 'LineName', width: 80,sortable:true },
                { field: 'HeaderName', title: '类别名称', width: 80 }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
        {
            $("#List").datagrid('load');
        }
        else
        {
            $("#List,#ListParent").datagrid('reload');
        }
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $.modalWindow(Lang.Create, '@Url.Action("Create")', 700, 400, 'fa fa-plus');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Edit, '@Url.Action("Edit")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-pencil');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Details, '@Url.Action("Details")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-list');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
	        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: queryStr });

        });
        $("#btnDelete").click(function () {
	            dataDelete("@Url.Action("Delete")", "List");
	        });
        $("#btnImport").click(function() {
             $("#txtExcelPath").val("");
             $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 155, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnExport").click(function() {
          $.post("@Url.Action("CheckExportData")", function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")";
                }
                else
                {
                $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });
    });
    function ImportData()
    {
        showLoading();
        var url = "@Url.Action("Import")?filePath="+$("#txtExcelPath").val();
        $.post(url, function(data) {
            if (data.type == 1)
            {
             $("#List").datagrid('load');
             $('#uploadExcel').window('close');
             $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
        }, "json");
    }
</script>

